package com.newsplatform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.newsplatform.entity.Category;
import com.newsplatform.entity.News;
import com.newsplatform.mapper.CategoryMapper;
import com.newsplatform.service.CategoryService;
import com.newsplatform.service.NewsService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 分类服务实现类
 * 
 * @author Logan.Li
 */
@Service
@RequiredArgsConstructor
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
    
    private final NewsService newsService;
    
    @Override
    public boolean hasNewsInCategory(Long categoryId) {
        QueryWrapper<News> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("category_id", categoryId);
        return newsService.count(queryWrapper) > 0;
    }
}
